<template>
	<view class="wrap">
		<view class="tips">
		
			

		</view>
		
		<view class="all-wrap">
			<view v-if="is_binding"  class="ipt-wrap" style="border-bottom:1px solid #9d9d9d">
				<view class="label">
					姓名
				</view>
				<view class="right">
					 {{pageData.real_name}}
				</view>
				
			</view>
			<view v-if="is_binding" class="ipt-wrap">
				<view class="label">
					<image :src="pageData.avatar" mode=""></image>
				</view>
				<view class="right">
					  {{pageData.nickname}}
				</view>
				
			</view>
			<view v-else class="ipt-wrap">
				<view class="label">
					姓名：
				</view>
				<view class="right">
					   <input  v-model="real_name"  type="text" placeholder="与微信实名一致的姓名" />
				</view>
				
			</view>
		</view>
		
		
		<view class="next" @click="genghuan" v-if="is_binding">
			更换绑定微信
		</view>
		<view v-else class="next" @click="bangding">
			绑定微信
		</view>
		<paypass ref="yspay" @cancel="cancelpay" @submit="submitpay"></paypass>
	</view>
</template>


<script>
	import paypass from "@/components/ys-paypass/ys-paypass.vue";
	export default {
		components:{
			paypass
		},
		data() {
			return {
				is_binding:true,
				pageData:{},
				real_name:'',
				bank_card:'',
				bank_of_deposit:'',
				bank_user:''
			}
		},
		onLoad() {
			
			this.getData()
		},
		methods: {
			
			genghuan(){
				this.is_binding=false
			},
		
			getData(){
				let that=this
				
				that.apiget('/api/user/get_wx_info').then(res => {
					if(res.Code==10200){
						let data=res.Data
						
						
						that.is_binding=data. is_binding 
						if(data. is_binding){
							that.pageData=data.user_info
							uni.setNavigationBarTitle({
								title: '已绑定'
							});
						}else{
							uni.setNavigationBarTitle({
								title: '未绑定'
							});
							
						}
						
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			bangding(){
				if(this.real_name==''){
					uni.showToast({
					    title: '请输入姓名',
					    duration:4000,
						icon:'none'
					});
					return
				}
				this.$refs.yspay.show();
			},
			submitpay(ex){
				
				this.subData(ex.value)
			},

			subData(pwd){
				let that=this
				
				
				
				uni.showModal({
					title: '提示',
					content: '确认您提交的姓名与微信实名一致，否则将会提现失败',
					success: function (res) {
						if (res.confirm) {
								uni.login({
								  provider: 'weixin',
								  success: function (loginRes) {
									that.apipost('/api/user/submit_wx_info',{
										real_name:that.real_name,
										pwd,
										access_token:loginRes.authResult.access_token,
										open_id:loginRes.authResult.openid
									
									},true).then(res => {
										if(res.Code==10200){
											let data=res.Data
																	
																	
											that.is_binding=data. is_binding 
											if(data. is_binding){
												that.pageData=data.user_info
												uni.setNavigationBarTitle({
													title: '已绑定'
												});
											}else{
												uni.setNavigationBarTitle({
													title: '未绑定'
												});
												
											}
						
											uni.showToast({
											    title: res.Message,
											    duration:4000,
												icon:'none'
											});
											
										}
										
									}).catch(err=>{
										console.log(err)
									});
								  },
								  fail:function(err){
									  uni.showToast({
									      title: err.errMsg,
									      duration:4000,
									  	icon:'none'
									  });
									  console.log(err)
								  }
								});
								
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
			}
		}
	}
</script>

<style>
	.forget{
		display:flex;
		justify-content: flex-end;
		padding-top:20rpx;
		color:#1380db;
		width:640rpx;
		margin:0 auto;
	}

	.label uni-image{
		height:60rpx;
		width:60rpx;
	}
	.next{
		
		background:#f9436b;
		color:#fff;
		width:640rpx;
		margin:0 auto;
		display:flex;
		justify-content: center;
		align-items: center;
		height:80rpx;
		margin-top:60rpx;
		border-radius:12rpx;
	}
	.ipt-wrap .label{
		width:160rpx;
		padding-left:30rpx;
	}
	.ipt-wrap .right{
		flex:1;
	}
	.right input{
		height:100%;
	}
	.ipt-wrap{
		background:#fff;
		display:flex;
		align-items: center;
		
		height:110rpx;
		
		
		
	}

	/* .name-wrap{
		border-bottom:1rpx solid #e8e8e8
	} */
	.wrap{
		background:#f7f7f7;
		min-height:100%;
	}
	.tips{
		color:#333;
		
		
		padding:14rpx 44rpx 34rpx 30rpx;
	}
	.all-wrap{
		width:640rpx;
		margin:0 auto;
		background: #fff;
		box-sizing: border-box;
		padding:0 34rpx;
		border-radius: 16rpx;
	}
</style>
